<!DOCTYPE html>
<html lang="en">
<head>
<title>用户登录</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<script type="text/javascript" src="../../staticFile/js/common/mobileCommon.min.js"></script>
<link type="text/css" rel="stylesheet" href="../../staticFile/css/mobile/common.css">
<style type="text/css">
body{background-color: #efefef;height: auto;}
.user-register{text-align: center;}
.register-phone{text-align: center;margin-top: 0.8rem;}
.user-register hr{border:none;height:0.1rem;background: url(../../staticFile/images/userIndex/menu-spacer.gif) repeat-x;}
#lglUserName,#lglUserPwd{-webkit-box-shadow: 0 0 0px 1000px white inset;}
.register-phone input{width: 90%;background-color:#fff !important;font-size: 0.6rem;line-height: 0.8rem;border: 0.05rem solid white;}
.register-phone .btn-next{background: url(../../../static/images/userIndex/menu-spacer.gif) repeat-x;border: 0rem;margin-top: 0.6rem;color: white;background-size: 100% 0.8rem;}
#errorMsg{text-align: center;background: white;color: red;margin-top: 0.4rem;}
.oth-info{text-align: right;margin-top: 0.4rem;font-size: 0.5rem;}
</style>
<script type="text/javascript" src="../../staticFile/js/common/constant.js"></script>
<script type="text/javascript" src="../../staticFile/js/plugins/jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../staticFile/js/plugins/encryption/scs_sha1.js"></script>
</head>
<body>
<div id="middleMain" class="middle-main">
    <div class="user-register">
        <h4 style="font-size: 0.6rem;">用户登录</h4>
        <hr />
    </div>
    <div id="writePhone" class="register-phone">
        <input type="text" id="lglUserName" placeholder="手机号码" autocomplete="new-text"/>
        <input type="password" id="lglUserPwd" placeholder="登录密码" autocomplete="new-password" style="margin-top: 0.6rem;"/>
        <input id="btnLogin" type="button" class="btn-next" value="登     录"/>
        <div class="oth-info">
            <a>没有帐号？</a>
            <a style="text-decoration:underline;" href="mUserRegister.html">我要注册</a>
            <a>|</a>
            <a style="text-decoration:underline;margin-right:5%;" href="mForgetPassword.html">忘记密码?</a>
        </div>
    </div>
    <div id="errorMsg"></div>
</div>
</body>
</html>
<script type="text/javascript">
$(function(){
    var up = sessionStorage.getItem(SCS_USER_PHONE);
    if (up != null) {
        $('#lglUserName').val(up);
    }
    //输入手机号码后的下一步
    $('#btnLogin').click(function(){
        var lglUserName = $('#lglUserName').val(), lglUserPwd = $('#lglUserPwd').val();
        if (lglUserName == null || lglUserName == ''){
            showErrorMsg('请输入登录手机号');
            return;
        }
        if (lglUserPwd == null || lglUserPwd == ''){
            showErrorMsg('请输入登录密码');
            return;
        }
        iAmLogin(lglUserName,lglUserPwd);
    });
});
//我要登录
function iAmLogin(userName,userPassword) {
	$('#btnLogin').attr("disabled",true);
	$('#btnLogin').val('正在登录...');
	var shaObj = new jsSHA("SHA-1", "TEXT");
	shaObj.update(userPassword);
	var hashPassword = shaObj.getHash("HEX");
	$.ajax({
		type : "POST",
		url : '/userIndex/user/toLogin',
		data : {
			userName : userName,
			userPassword : hashPassword,
			isMobile: 'Y'
		},
		dataType : 'json',
		cache : false,
		async: false,
		success : function(result) {
			var msg = '', s = result.status;
			if ("0" == s) {
				sessionStorage.setItem(SCS_USER_NAME, userName);
				sessionStorage.setItem(SCS_USER_PHONE, result.userPhone);
				sessionStorage.setItem(SCS_USER_ID, result.userId);
				//sessionStorage.setItem(SCS_UNAME, result.uname);
				var lastRequestUrl = sessionStorage.getItem('lastRequestUrl');
				//如果上一次请求路径不为空，则直接跳转到上一次请求的路径
				if(lastRequestUrl != null && lastRequestUrl != ''){
					sessionStorage.removeItem('lastRequestUrl');
					window.location.href = lastRequestUrl;
				}else{
					var thisPagePath = window.document.location.href;
					if (thisPagePath.indexOf('mUserLogin') > -1) {//如果是登录页面，就跳转到首页，否则不跳转
						window.location.href = '/userPages/mobile/mIndex.html';
					}
				}
			} else if (s == '1') {
				msg = '用户名或密码不能为空';
			} else if (s == '2' || s == '4') {
				msg = '验证失败，请拖动滑块完成验证';
			} else if (s == '3') {
				msg = '用户名或密码错误';
			} else if (s == '5') {
				msg = '您的账户已被冻结，如有疑问请联系客服';
			}
			$('#btnLogin').attr("disabled",false);
			$('#btnLogin').val('登录');
			showErrorMsg(msg);
		},
		error: function() {
			$('#btnLogin').attr("disabled",false);
			$('#btnLogin').val('登录');
			showErrorMsg('登录失败');
			sessionStorage.removeItem(SCS_USER_NAME);
		}
	});
}
function showErrorMsg(emStr){
    var em = $('#errorMsg');
    em.text(emStr);
    em.show();
    var errorTimeout = window.setTimeout(function(){
        em.hide();
        window.clearTimeout(errorTimeout);
    }, 1000 * 6);
}
</script>